package com.czxy.controller;

import com.czxy.dao.CommodityDao;
import com.czxy.domain.Commodity;
import com.czxy.domain.CommodityVo;
import com.czxy.service.CommodityService;
import com.czxy.vo.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/11
 */
@RestController
@RequestMapping("/commdity")
public class CommodityController {

    @Resource
    private CommodityService commodityService;

    //分页 查询 商品
    @PostMapping("/findAllCommodity")
    public BaseResult findAllCommodity(@RequestBody CommodityVo commodityVo){
        PageInfo<Commodity> pageInfo = commodityService.findAllCommodity(commodityVo);
        return BaseResult.ok("查询成功",pageInfo);
    }

    //分页 查询 缺少商品
    @PostMapping("/findAllCommodityQS")
    public BaseResult findAllCommodityQS(@RequestBody CommodityVo commodityVo){
        PageInfo<Commodity> pageInfo = commodityService.findAllCommodityQS(commodityVo);
        return BaseResult.ok("查询成功",pageInfo);
    }

    //修改 商品
    //checkoutBycid
    @GetMapping("/checkoutBycid/{cid}")
    public BaseResult checkoutBycid(@PathVariable("cid")Integer cid){
        Commodity commodity = commodityService.checkoutBycid(cid);
        return BaseResult.ok("查询成功",commodity);
    }

    //修改二
    @PutMapping("/updateCommodity")
    public BaseResult updateCommodity(@RequestBody Commodity  commodity){
        commodityService.updateCommodity(commodity);
        return BaseResult.ok("修改成功");
    }

    @PutMapping("/updateCommodityNumber/{cid}")
    public BaseResult updateCommodityNumber(@PathVariable("cid")Integer cid){
        commodityService.updateCommodityNumber(cid);
        return BaseResult.ok("采购成功");
    }

}
